package cn.net.ecode.elec.api.web;

import cn.net.ecode.annotation.Login;
import cn.net.ecode.annotation.LoginUser;
import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.mapper.JsonMapper;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.utils.JedisUtils;
import cn.net.ecode.common.utils.StringUtils;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.constant.LoginTypeEnum;
import cn.net.ecode.constant.SendSmsTypeEnum;
import cn.net.ecode.elec.api.entity.LoginForm;
import cn.net.ecode.elec.api.entity.SubAdminForm;
import cn.net.ecode.elec.api.service.ElecUserService;
import cn.net.ecode.mdm.entity.MdmBtypeInfo;
import cn.net.ecode.modules.cms.entity.Article;
import cn.net.ecode.modules.cms.entity.Category;
import cn.net.ecode.modules.cms.entity.Site;
import cn.net.ecode.modules.cms.service.ArticleService;
import cn.net.ecode.modules.sys.entity.User;
import cn.net.ecode.modules.sys.service.UserService;
import cn.net.ecode.util.FileUploadUtils;
import cn.net.ecode.util.JwtUtils;
import cn.net.ecode.util.R;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AppUserController
 * @Description 用户注册接口
 * @Author AlanShelby
 * @Date 2019/8/27 0027 8:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/cms")
public class AppCmsController extends BaseController {
    @Autowired
    private ArticleService articleService;

    /**
     * 获取cms page
     *
     * @param siteCode
     * @param categoryCode
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Login
    @RequestMapping(value = "articleList", method = RequestMethod.GET)
    public Page<Article> articleList(@RequestParam String siteCode, @RequestParam String categoryCode, @RequestParam int pageNo, @RequestParam int pageSize) {
        if (!StringUtils.isBlank(siteCode) && !StringUtils.isBlank(categoryCode)) {
            Category category = new Category();
            category.setSite(new Site(siteCode));
            Page<Article> page = new Page();
            page.setPageNo(pageNo);
            page.setPageSize(pageSize);

            if (!"0".equals(categoryCode)) {
                category.setCategoryCode(categoryCode);
                category.setParentCodes(categoryCode);
            }
            Article article = new Article(category);
            article.setStatus("0");
            page = articleService.findPage(page, article, false);
            return page;
        } else {
            return new Page<>();
        }
    }
}
